using UnityEngine;
using System.Collections.Generic;
using System;

/// <summary>
/// Db logic for the game object Item
/// </summary>
public class GameItemDbLogic : IDTODbLogic<GameItem>
{
	#region IDTODbLogic[GameItem] implementation
	public GameItem CreateShallowObjectFromDataRow (System.Data.DataRow row)
	{
		GameItem newItem = new GameItem();
		newItem.GameItemId = row["game_item_id"].ToString();
		newItem.GameItemTypeCd = row["game_item_type_cd"].ToString();
		return newItem;
	}

	public string SelectStatement {
		get 
		{
			return "SELECT game_item_id, game_item_type_cd from game_item";
		}
	}

	public void PopulateChildObjects (GameItem objectToMap, GameDatabase gameDatabase)
	{
		if (objectToMap == null) { return; }
		
		DTORepository<GameItemType> itemTypeRepository = DTORepository<GameItemType>.GetInstance(new GameItemTypeDbLogic());
		List<GameItemType> itemTypeList = itemTypeRepository.FindAll(gameDatabase);
		foreach(GameItemType it in itemTypeList)
		{
			if (it.GameItemTypeCd == objectToMap.GameItemTypeCd) 
			{
				objectToMap.GameItemType = it;
				break;
			}
		}
	}
	#endregion

}

